

public class StructLinkedList {

	HarvestNode first;
	HarvestNode last;
	int amount, type;
	final int FOOD =1,	METAL = 2, POWER = 3;
	
	public StructLinkedList(int _type){
		amount = 0;
		first = null;
		last = null;
		type = _type;
	}
	
	
	// ========== GETTERS ============
	
	
	
	// ========== SETTERS ============
	
	
	
	// ========== DO STUFF ===========
	public void add(Tile temp){
		amount++;
		HarvestNode x = new HarvestNode(temp, type);
		if(amount == 1){
			first = x;
			last = x;
		}
		else{
			last.next(x);
			x.previous(last);
			last = x;
		}
		
	}
	public String toString(){
		HarvestNode node = first;
		String s= "";
		while(true){
			if(node != null){
				s += node.toString()+", ";
				node = node.next();
			}
			else
				break;
			
		}
		return s;
	}
	public boolean contains(Tile temp){
		
		HarvestNode node = first;
		while(true)
			if(node.equals(temp))
				return true;
			else if(node.hasNext()){
				node = node.next();
			}
			else
				break;		
		return false;
	}

	public boolean remove(Tile temp){
		HarvestNode node = first;
		
		while(true){
			if(node.equals(temp)){
				System.out.println("-");
				node.remove();
				amount--;
				return true;
			}
			else if(node.hasNext()){
				node = node.next();
			}
			else
				break;
		}
		
		return false;
	}

	public int harvest(){
		int harvest=0;
		HarvestNode node = first;
		while(true){
			if(node!= null)	
				harvest += node.harvest();
			else
				break;
			node = node.next();
		}
		return harvest;
	}
	
	public boolean assign(int num, Tile tile){
		HarvestNode node = first;

		
		while(true){
			if(node.equals(tile)){
				node.assign(num);
				return true;
			}
			else if(node.hasNext()){
				node = node.next();
			}
			else
				break;
		}
		
		return false;
	}
	
	public int unassign(int num, Tile tile){
		HarvestNode node = first;

		while(true){
			if(node.equals(tile))
				return node.unassign(num);
			else if(node.hasNext()){
				node = node.next();
			}
			else
				break;
		}
		
		return -1;
	}
	
	public void die(){
		HarvestNode node = first;
		
		while(node!= null)
			node.die();
	}

}
